﻿using CodeGenerator.ClassServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeGenerator.Models
{
    class RelationshipModel
    {
        
        public int Id { get; set; }
        public string Name { get; set; }
        public int SourceClassId { get; set; }
        public int SourceMulticity { get; set; }
        public bool SourceNavigable { get; set; }
        public int DestClassId { get; set; }
        public int DestMulticity { get; set; }
        public bool DestNavigable { get; set; }
        public RelationshipType SourceType { get; set; } 
        public RelationshipType DestType { get; set; }      
        public AttributeModel SourceAttribute { get; set; }      
        public AttributeModel DestAttribute { get; set; }     
        public List<LookupModel> LookupModels { get; set; }

        //public void SetSourceType(RelationshipType sourceType)
        //{
        //    SourceType = sourceType;
        //}
        //public void SetDestType(RelationshipType destType)
        //{
        //    DestType = destType;
        //}

        public RelationshipModel() { }

        internal RelationshipModel(RelationshipModelDto dto)
        {
            this.Id = dto.Id;
            this.Name = dto.Name;
            this.SourceClassId = dto.SourceClassId;
            this.SourceMulticity = dto.SourceMulticity;
            this.SourceNavigable = dto.SourceNavigable;
            this.DestClassId = dto.DestClassId;
            this.DestMulticity = dto.DestMulticity;
            this.DestNavigable = dto.DestNavigable;
            this.SourceType = new RelationshipType(dto.SourceType);
            this.DestType = new RelationshipType(dto.DestType);
            this.SourceAttribute = new AttributeModel(dto.SourceAttribute);
            this.DestAttribute = new AttributeModel(dto.DestAttribute);
            this.LookupModels = new List<LookupModel>();

            foreach (LookupModelDto lookup in dto.LookupDetails)
            {
                this.LookupModels.Add(new LookupModel(lookup));
            }
        }
    }
}
